package za.org.meraka.cair.ontorepair;

import java.util.HashSet;
import java.util.Set;

import org.semanticweb.owlapi.model.*;

public class OntologyPartitioner {	
	private int numParts;
	private Set<OWLAxiom>[] axiomSet;			
	
	public OntologyPartitioner(OWLOntology o, int n){
		numParts = n;		
		axiomSet = new HashSet[n];
		for (int p = 0; p < n;p++)
			axiomSet[p] = new HashSet<OWLAxiom>();
		
		int i = 0;
		for (OWLAxiom tmp: o.getAxioms()){
			if (i == n){
				i = 0;
				axiomSet[i].add(tmp);
				i++;
			}
			else{
				axiomSet[i].add(tmp);
				i++;
			}														
		}					
	}	
	
	public Set<OWLAxiom> getPart(int i){
		if (i < numParts)
			return axiomSet[i];
		else{
			System.out.println("adding empty part...");
			return new HashSet<OWLAxiom>();
		}
	}
	
	public Set<OWLAxiom> combine(int j){
		Set<OWLAxiom> resultSet = new HashSet<OWLAxiom>();		
		for (int k = 0; k < numParts;k++){
			if (k != j)
				resultSet.addAll(axiomSet[k]);
		}		
		return resultSet;
	}
}
